# Maintainer: Caleb Maclennan <caleb@alerque.com>

pkgbase=lua-system
_rockname=${pkgbase#lua-}
pkgname=("$pkgbase" "lua51-$_rockname" "lua52-$_rockname" "lua53-$_rockname")
pkgver=0.2.1
_rockrel=0
pkgrel=9
pkgdesc='Platform independent system calls for Lua'
arch=(loong64 x86_64 i686)
url="https://github.com/o-lim/${pkgbase/-/}"
license=(MIT)
makedepends=(lua
             lua51
             lua52
             lua53
             luarocks)
checkdepends=(busted)
options=(debug)
_archive="${pkgbase/-/}-$pkgver"
_rock="$_archive-$_rockrel.linux-$CARCH.rock"
_rockspec="$_archive-$_rockrel.rockspec"
source=("$url/archive/v$pkgver/$_archive.tar.gz")
sha256sums=('0b83f68e9edbba92bef11ec0ccf1e5bb779a7337653f7bb77e0240c8e85c0b94')

build() {
	cd "$_archive"
	for LUAVER in 5.{1,2,3,4}; do
		luarocks --lua-version "$LUAVER" \
			make --pack-binary-rock --deps-mode none -- "$_rockspec"
		install -Dm0644 -t "lua-$LUAVER/" "$_rock"
	done
}

check() {
	cd "$_archive"
	busted
}

_package() {
	cd "$_archive"
	depends=("${pkgname%-*}")
	luarocks --lua-version "$1" --tree "$pkgdir/usr/" \
		install --deps-mode none --no-manifest -- "lua-$1/$_rock"
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE
}

package_lua-system() {
	_package 5.4
}

package_lua53-system() {
	_package 5.3
}

package_lua52-system() {
	_package 5.2
}

package_lua51-system() {
	_package 5.1
}
